04. HTTP Responses

HTTP Responses

FSND C2 L2 A05 HTTP Responses (Status Codes)

After the request has been received by the server and processed, the server returns an HTTP response message to the client. The response informs the client of the outcome of the requested operation.

Elements:

  • Status Code & Status Message
  • HTTP Version
  • Headers: similar to the request headers, provides information about the response and resource representation. Some common headers include:
    • Date
    • Content-Type: the media type of the body of the request
  • Body: optional data containing the requested resource

Status Codes:

As an API developer, it's important to send the correct status code. As a developer using an API, the status codes—particularly the error codes—are important for understanding what caused an error and how to proceed.

Codes fall into five categories:

  • 1xx Informational
  • 2xx Success
  • 3xx Redirection
  • 4xx Client Error
  • 5xx Server Error

Common Codes:

  • 200 : OK
  • 201 : Created
  • 304 : Not Modified
  • 400 : Bad Request
  • 401 : Unauthorized
  • 404 : Not Found
  • 405 : Method Not Allowed
  • 500 : Internal Server Error

QUIZ QUESTION: :

Match the response component with the element from the following example:

HTTP/2.0 200 OK
Date: Fri, 21 June 2019 16:17:18 GMT
Content-Type: text/html
Accept-Ranges: bytes
Body: {'success': True}

ANSWER CHOICES:



Component

Example Element

{'success': True}

OK

Accept-Ranges, Content-Type

200

HTTP/2.0

SOLUTION:

Component

Example Element

{'success': True}

OK

Accept-Ranges, Content-Type

200

HTTP/2.0

HTTP Basics Quiz

Which of the following request methods would receive a 201 status code after successful completion?

SOLUTION: POST

HTTP Basics Quiz 2

If there were an error processing the request, which category (or categories) of methods should be part of the response message?
(Select all that apply.)

SOLUTION:
  • 4xx
  • 5xx

There are a lot of status codes and it doesn't make sense to try to memorize them all. Fortunately, they're easy to look up.

There are lots of resources out there that list status codes, including one of my favorites:
HTTP Dogs

Using the above link (or a Google search), see if you can find out what a 405 status code means.

SOLUTION: Method Not Allowed